
const cardDefine = require("../game_model/cardDefine");
const CardDecor = cardDefine.CardDecor;

class CardMgr {

    // 获取花色
    getCardDecor(card) {
        return card % 10;
    }

    // 获取牌的值
    getCardValue(card) {
        return Math.floor(card / 10);
    }

    isRedCard(card) {
        var decor = this.getCardDecor(card);
        return decor == CardDecor.HEART || decor == CardDecor.BLOCK;
    }

    isBlackCard(card) {
        var decor = this.getCardDecor(card);
        return decor == CardDecor.SPADE || decor == CardDecor.PLUM;
    }

    isCard(card, targetCardValue, targetCardDecor) {
        if (this.getCardValue(card) != targetCardValue) return false;
        if (targetCardDecor != null) {
            if (this.getCardDecor(card) != targetCardDecor) return false;
        }
        return true;
    }

    hasCard(cards, targetCardValue, targetCardDecor) {
        for (var i = 0; i < cards.length; ++i) {
            if (this.isCard(cards[i], targetCardValue, targetCardDecor)) {
                return true;
            }
        }
        return false;
    }
}

exports.CardDecor = CardDecor;
exports.CardMgr = CardMgr;